home *** CD-ROM | disk | FTP | other *** search
/ The World's Largest Collection of Windows Software / The World's Largest Collection of Windows Software - Disc 1.iso / win / pro218 / filereco.pas < prev    next >
Pascal/Delphi Source File  |  1992-03-31  |  4KB  |  124 lines

  1. UNIT FileReco;
  2.   {-Provides the FileRecord object, for storing data about files,-}
  3.   {-and the FileRecordList object, a collection of FileRecords.  -}
  4.   {-Directories are stored using a pointer to a PStrCollection   -}
  5.   {-and an index into that collection.  The directory collection -}
  6.   {-must be complete *BEFORE* using these objects, and must not  -}
  7.   {-be changed while these objects are in use.                   -}
  8. (**) INTERFACE (**)
  9. USES WinTypes, WinProcs, WObjects, Strings;
  10. TYPE
  11.   PFileRecord = ^TFileRecord;
  12.   TFileRecord = OBJECT(TObject)
  13.     Name       : PChar;   {-Filename and extension only           -}
  14.     Flags      : Byte;    {-Bit 0 for directory; bit 1 for changed-}
  15.     Dir        : Word;    {-Index into DL; indicates the home ... -}
  16.     DL         : PStrCollection; {-directory for this file.       -}
  17.     Time, Size : LongInt; {-Date/time stamp and file size.        -}
  18.     CONSTRUCTOR Init(iName : PChar; yesDir : Boolean; iDir : Word;
  19.       iTime, iSize : LongInt; iDL : PStrCollection);
  20.     DESTRUCTOR Done; Virtual;
  21.     PROCEDURE SetChanged;
  22.     FUNCTION GetDir    : Word;
  23.     FUNCTION GetTime   : LongInt;
  24.     FUNCTION GetSize   : LongInt;
  25.     FUNCTION GetName   : PChar;
  26.     FUNCTION IsDir     : Boolean;
  27.     FUNCTION IsChanged : Boolean;
  28.     FUNCTION GetFullName(P : PChar) : PChar;
  29.   END;
  30.  
  31.   PFileRecordList = ^TFileRecordList;
  32.   TFileRecordList = OBJECT(TSortedCollection)
  33.       {-A sorted collection of PFileRecords-}
  34.     FUNCTION Compare(Key1, Key2 : Pointer) : Integer; Virtual;
  35.   END;
  36.  
  37.   PStrICollection = ^TStrICollection;
  38.   TStrICollection = OBJECT(TStrCollection)
  39.       {-Just like a TStrCollection, but Compare is case-insensitive-}
  40.     FUNCTION Compare(Key1, Key2 : Pointer) : Integer; Virtual;
  41.   END;
  42.  
  43. (**) IMPLEMENTATION (**)
  44. CONST
  45.   fr_Dir     = 1;
  46.   fr_Changed = 2;
  47. {--------------------------------------------------}
  48. { TFileRecordList's methods                        }
  49. {--------------------------------------------------}
  50.  
  51.   FUNCTION TFileRecordList.Compare(Key1, Key2 : Pointer) : Integer;
  52.   VAR
  53.     K1 : PFileRecord ABSOLUTE Key1;
  54.     K2 : PFileRecord ABSOLUTE Key2;
  55.   BEGIN
  56.       {-The list of directories is sorted, so if the Dir field of-}
  57.       {-one PFileRecord is less/greater than that of another, the-}
  58.       {-whole record is considered less/greater.  If Dir is the  -}
  59.       {-same, less/greater is determined by a case-insensitive   -}
  60.       {-comparison of the filenames.                             -}
  61.     IF K1^.GetDir < K2^.GetDir THEN Compare := -1
  62.     ELSE IF K1^.GetDir > K2^.GetDir THEN Compare := 1
  63.     ELSE Compare := StrIComp(K1^.GetName, K2^.GetName);
  64.   END;
  65.  
  66. {--------------------------------------------------}
  67. { TFileRecord's methods                            }
  68. {--------------------------------------------------}
  69.   CONSTRUCTOR TFileRecord.Init(iName : PChar; yesDir : Boolean;
  70.     iDir : Word; iTime, iSize : LongInt; iDL : PStrCollection);
  71.   BEGIN
  72.     TObject.Init;
  73.     Name  := StrNew(iName);
  74.     Flags := Ord(yesDir);
  75.     Dir   := iDir;
  76.     Time  := iTime;
  77.     Size  := iSize;
  78.     DL    := iDL;
  79.   END;
  80.  
  81.   DESTRUCTOR TFileRecord.Done;
  82.   BEGIN
  83.     StrDispose(Name);
  84.     TObject.Done;
  85.   END;
  86.  
  87.   PROCEDURE TFileRecord.SetChanged;
  88.   BEGIN Flags := Flags OR fr_Changed; END;
  89.  
  90.   FUNCTION TFileRecord.GetDir : Word;
  91.   BEGIN GetDir := Dir; END;
  92.  
  93.   FUNCTION TFileRecord.GetTime : LongInt;
  94.   BEGIN GetTime := Time; END;
  95.  
  96.   FUNCTION TFileRecord.GetSize : LongInt;
  97.   BEGIN GetSize := Size; END;
  98.  
  99.   FUNCTION TFileRecord.GetName : PChar;
  100.   BEGIN GetName := Name; END;
  101.  
  102.   FUNCTION TFileRecord.GetFullName(P : PChar) : PChar;
  103.     {-PChar P must be allocated by CALLING routine.-}
  104.   BEGIN
  105.     StrCopy(P, PChar(DL^.At(Dir)));
  106.     StrCat(P, Name);
  107.     GetFullName := P;
  108.   END;
  109.  
  110.   FUNCTION TFileRecord.isDir : Boolean;
  111.   BEGIN IsDir := Flags AND fr_Dir <> 0; END;
  112.  
  113.   FUNCTION TFileRecord.isChanged : Boolean;
  114.   BEGIN IsChanged := Flags AND fr_Changed <> 0; END;
  115.  
  116. {--------------------------------------------------}
  117. { TStrICollection's methods                        }
  118. {--------------------------------------------------}
  119.   FUNCTION TStrICollection.Compare(Key1, Key2: Pointer): Integer;
  120.   BEGIN
  121.     Compare := StrIComp(Key1, Key2);
  122.   END;
  123.  
  124. END.